<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>洗车订单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/public/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/public/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">

                        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                            <div class="layui-form-item">

                                <div class="layui-inline">
                                    <label class="layui-form-label">手机号</label>
                                    <div class="layui-input-block" style="width: 300px;">
                                        <input class="layui-input" name="mobile" placeholder="请输入手机号" autocomplete="off">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">车牌号</label>
                                    <div class="layui-input-block" style="width: 300px;">
                                        <input class="layui-input" name="license" placeholder="请输入车牌号" autocomplete="off">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">订单号</label>
                                    <div class="layui-input-block" style="width: 300px;">
                                        <input class="layui-input" name="orderNo" placeholder="请输入订单号" autocomplete="off">
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <label class="layui-form-label">用户编号</label>
                                    <div class="layui-input-block" style="width: 300px;">
                                        <input class="layui-input" name="userId" placeholder="请输入用户编号" autocomplete="off">
                                    </div>
                                </div>

                                <div class="layui-inline layui-form">
                                    <label class="layui-form-label">订单状态</label>
                                    <div class="layui-input-block" style="width: 200px;">
                                        <select name="status">
                                            <option value="">请选择类型</option>
                                            <option value="0">待提交</option>
                                            <option value="1">待支付</option>
                                            <option value="2">已支付</option>
                                            <option value="3">待洗车</option>
                                            <option value="4">洗车中</option>
                                            <option value="5">洗车完成</option>
                                            <option value="6">异常</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="layui-inline layui-form">
                                    <label class="layui-form-label">退款状态</label>
                                    <div class="layui-input-block" style="width: 200px;">
                                        <select name="refundStatus">
                                            <option value="">请选择类型</option>
                                            <option value="0">无退款</option>
                                            <option value="1">待退款</option>
                                            <option value="2">已退款</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="layui-inline">
                                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-search">
                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"> 搜索</i>
                                    </button>
                                </div>
                            </div>
                        </div>
                        <table class="layui-hide" id="test-table-reload" lay-filter="test-table-reload"></table>

                        <script type="text/html" id="test-table-reload-barDemo">
                            <a class="layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/order/detail')} layui-hide #{/if}" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>查看详情</a>
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/public/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/public/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table','utils', 'form'], function(){
        var $ = layui.$,
                table = layui.table,
                form = layui.form,
                admin = layui.admin;

        //监听搜索
        form.on("submit(LAY-search)", function (data) {
            var field = data.field;

            //执行重载
            table.reload('test-table-reload', {
                where: field
            });
        });

        //方法级渲染
        table.render({
            elem: '#test-table-reload'
            ,url: "/order/getOrderList"
            ,toolbar: '#test-table-reload-toolbar'
            ,defaultToolbar:['filter']
            ,cellMinWidth: 80
            ,cols: [[
                {field:'userId', title: '用户编号', fixed: true}
                , {field:'userMobile', title: '手机号'}
                , {field:'orderNo', title: '洗车订单'}
                , {field:'goodsName', title: '商品名称'}
                , {field:'amount', title: '实际支付'}
                , {field:'statusName', title: '订单状态'}
                , {field:'refundStatus', title: '退款状态', templet: refundStatus}
                , {field:'payTypeName', title: '支付方式'}
                , {field:'carNo', title: '车牌号'}
                , {field:'stationId', title: '站点编号',width:100}
                , {field:'stationName', title: '站点名称'}
                , {field:'createTime', title: '创建时间',sort: true,templet: function (d) {
                        return "<div>"+layui.toDateString(d.createTime)+"</div>";
                    }}
                , {fixed: 'right', title:'操作', toolbar: '#test-table-reload-barDemo', width:100}
            ]]
            ,page: true
            ,height: 522
        });


        //监听行工具事件
        table.on('tool(test-table-reload)', function(obj){
            var data = obj.data;
            var id = data.id;
            var userId=data.userId;
            if(obj.event === 'edit'){
                layer.open({
                    type: 2
                    ,title: "订单详情"
                    ,content: '/order/detail?id='+id+"&userId="+userId
                    ,area: ['1200px', '700px']
                    ,btn: ['取消']
                });
            } else if(obj.event === 'refundAudit'){
                layer.open({
                    type: 2
                    ,title: '处理退款审核'
                    ,content: '/order/audit?id='+id+"&userId="+userId
                    ,area: ['600px', '400px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                                ,submit = layero.find('iframe').contents().find("#editRefundAuditSubmit");

                        //监听提交
                        iframeWindow.layui.form.on('submit(editRefundAuditSubmit)', function(data){
                            var field = data.field; //获取提交的字段

                            $.post("/order/savAudit", field, function (result) {
                                if (result.code > 0) {
                                    layer.msg(result.msg);
                                }
                            });
                            //table.reload('test-table-reload');
                            layer.close(index); //关闭弹层
                            window.location.reload();
                        });

                        submit.trigger('click');
                    }
                });
            }
        });
        function refundStatus(data) {
            if(data.refundStatus == 0){
                return "<div>"+ "无退款"+"</div>";
            }
            if(data.refundStatus == 1){
                return "<div class='layui-btn layui-btn-xs #{if !toolsUtils.checkBtn('/order/audit')} layui-hide #{/if}' lay-event='refundAudit'>"+ "待退款"+"</div>";
            }
            if(data.refundStatus == 2){
                return "<div>"+ "已退款"+"</div>";
            }
        }
    });
</script>
</body>
</html>